![]() news about forums links tools tutorials contact |
| Scrolling CTF Banner - author: ob1-kenobi | |
This tutorial goes through whats involved to create a custom
scrolling banner like the one in DM-Morpeus, and how to use it in a map.
The scrolling message banner thats used in some UT maps
comes in two parts, the message script actor and the scripted texture
which is used to generate RenderTexture() calls in the script actor.
Firstly, lets take a look at the ClientScriptedTexture class. The 'ScriptedTexture' property should be set up when you add
the class to the level. When the game begins, the texture's 'NotifyActor'
is set as this script actor. This will allow the actor to recieve
'RenderTexture()' calls when the texture is drawn during the game. Notice that the functions are all 'simulated' so that they
can be called on the client. You don't need to worry about why they are
simulated for the tutorial, just that they need to be made 'simulated' for
it to work properly. Now on to the banner code. For this tutorial, we'll be
sub-classing the ScrollingMessageTexture and modify it slightly to make
our own CTF banner. Here's the code for that class. This is the main entry point, and is the function that does
most of the work. It calls the FindPlayer() function to try to find the
local player (ie. the person actually playing the game) so that it can
grab a reference to the GameReplicationInfo class, and it calls Replace()
to replace the macros with the relavent text. The first part of the function tries to find the local
player, and ends the function if no local player can be found, or the
player doesn't have a GameReplicationInfo reference. The next part is involved with the posisioning of the
scrolling message on the main texture. It does this by keeping track of
the time that last frame was drawn, and adjusts it based on the time
passed since the last render multiplyed by the value of PixelsPerSecond.
If the message Position is less that the ScrollWidth, the position is
reset. The position has been worked out, the message string is
processed and the macros are replaced with the relevant text. The code
below replaces the %h macro with a gender specific string depending on the
gender of the local player. The next section of code replaces the %p macro with the
player name, and if either the %lf or %lp macros are in the message string
replaces those with the leading players name and score. Finally, the string is changed to uppercase if necessary,
saved to OldText and drawn on the Texture. For the CTF message we need to use the team info rather than
the players, so we need to get the information from the Teams[] array in
TournamentGameReplicationInfo instead. Also, a message will be needed for
when the teams scores are tied. The scrolling message will need 2 macros, one for the
leading teams name, and one for the leading teams score. These will be %t
for the team name and %s for the teams score. Having the score displayed
when the teams are tied will also be useful, but the %s macro can be used
for this too as it doesn't matter which teams score is used when the teams
are tied. Here's the complete code for the class: Ok, now that we have the code for the new scrolling message,
its time to add it to a map. There are two ways that you can do this. You can either
compile the class as a separate package and add it to the map that way, or
you can import the class directly in to a map. If you compile it as a separate package, the map will need
to load the package when the map is loaded and it will probably have to be
listed on the server packages list to work. By importing it to the map,
you remove the need for an external package. I'll cover this method first.
Both of these methods use UnrealEd2. Ok, firt things first: Make a backup of your map.
Now open up the class browser (the one used for selecting an
actor to add to a map) and select
Actor->Info->ClientScriptedTexture->ScrollingMessageTexture.
Right click on the ScrollingMessageTexture class and select "New...". Now
fill in the boxes as the following: Package: MyLevel Then click on "OK". When the code window pops up, replace *all* the code in the
window with the code for the BasicScrollingCTFMessage class from above.
After this is done, select: Tools | Compile changed to compile the script.
If there are any errors, check that you have: If it compiled ok, save the map. The class is now embedded
in your CTF map. If you'd rather not import the class in to your map, you can
import it in to regular .u package and add it to your map from there. This
will mean that the package has to be distributed with the map, and may
cause complications if trying to download the map off a server. Open up the class browser (the one used for selecting an
actor to add to a map) and select
Actor->Info->ClientScriptedTexture->ScrollingMessageTexture.
Right click on the ScrollingMessageTexture class and select "New...". Now
fill in the boxes as the following: Package: name_of_package Where name_of_package is what you want the new package to be
called. When the code window pops up, replace *all* the code in the
window with the code for the BasicScrollingCTFMessage class from above.
After this is done, select: Tools | Compile changed to compile the script.
If there are any errors, check that you have: If it compiled ok, select the new package from the package
list in the class browser (if no packages are listed, select "View | Show
packages" to display them) and then select "File | Save selected packages"
to save the package. I don't really want to go over how to set up a scrolling
message banner, so I'll assume that you already know how and continue from
there. Check out the UnrealEd sites for tutorials on it if you are unsure
of how to set one up, or check out some of the maps that use them like
DM-Morhpeus, etc. Once you've set up the map surface with the scripted texture
you want to use, add the custom BasicScrollingCTFMessage to the map
instead of a ScrollingMessageTexture. Set up the properties just as you
would a regular message banner, except set up the ScrollingMessage and
ScoresTiedMessage to use the CTF macros instead, eg. "%t leads with %s
captures." for ScrollingMessage, and "Both teams are tied with %s
captures." for the ScoresTiedMessage. | |